package com.mysteel.cyx.ddd.application.converter;

import com.mysteel.cyx.ddd.application.dtos.MyDto;
import com.mysteel.cyx.ddd.domain.model.entity.MyEntity;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class MyEntityDtoConverter implements EntityDtoConverter<MyEntity, MyDto> {

    @Override
    public MyDto convertToDto(MyEntity entity) {
        // 将MyEntity对象转换为MyDto对象的逻辑
        return new MyDto(entity.getName());
    }

    @Override
    public MyEntity convertToEntity(MyDto dto) {
        // 将MyDto对象转换为MyEntity对象的逻辑
        return new MyEntity(dto.getName());
    }


    @Override
    public List<MyDto> convertToDtoList(List<MyEntity> entityList) {
        return entityList.stream()
                .map(this::convertToDto)
                .collect(Collectors.toList());
    }

    @Override
    public List<MyEntity> convertToEntityList(List<MyDto> dtoList) {
        return dtoList.stream()
                .map(this::convertToEntity)
                .collect(Collectors.toList());
    }
}
